package cn.iocoder.yudao.module.wine.controller.admin.commentreport;

import cn.iocoder.yudao.module.wine.controller.app.complaincomment.vo.AppComplainCommentRespVO;
import cn.iocoder.yudao.module.wine.service.complaincomment.ComplainCommentService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.admin.commentreport.vo.*;
import cn.iocoder.yudao.module.wine.dal.dataobject.commentreport.CommentReportDO;
import cn.iocoder.yudao.module.wine.service.commentreport.CommentReportService;

@Tag(name = "管理后台 - 评论举报记录")
@RestController
@RequestMapping("/wine/comment-report")
@Validated
public class CommentReportController {

    @Resource
    private CommentReportService commentReportService;

    @Resource
    private ComplainCommentService complainCommentService;

    @PostMapping("/create")
    @Operation(summary = "创建评论举报记录")
    @PreAuthorize("@ss.hasPermission('wine:comment-report:create')")
    public CommonResult<Long> createCommentReport(@Valid @RequestBody CommentReportSaveReqVO createReqVO) {
        return success(commentReportService.createCommentReport(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新评论举报记录")
    @PreAuthorize("@ss.hasPermission('wine:comment-report:update')")
    public CommonResult<Boolean> updateCommentReport(@Valid @RequestBody CommentReportSaveReqVO updateReqVO) {
        commentReportService.updateCommentReport(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除评论举报记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('wine:comment-report:delete')")
    public CommonResult<Boolean> deleteCommentReport(@RequestParam("id") Long id) {
        commentReportService.deleteCommentReport(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得评论举报记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wine:comment-report:query')")
    public CommonResult<CommentReportRespVO> getCommentReport(@RequestParam("id") Long id) {
        CommentReportDO commentReport = commentReportService.getCommentReport(id);
        return success(BeanUtils.toBean(commentReport, CommentReportRespVO.class));
    }

    @GetMapping("/get-comment")
    @Operation(summary = "获得评论信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wine:comment-report:query')")
    public CommonResult<AppComplainCommentRespVO> getComment(@RequestParam("commentId") Long commentId) {
        AppComplainCommentRespVO complainComment = complainCommentService.getComplainCommentById(commentId);
        return success(complainComment);
    }

    @GetMapping("/page")
    @Operation(summary = "获得评论举报记录分页")
    @PreAuthorize("@ss.hasPermission('wine:comment-report:query')")
    public CommonResult<PageResult<CommentReportRespVO>> getCommentReportPage(@Valid CommentReportPageReqVO pageReqVO) {
        PageResult<CommentReportRespVO> pageResult = commentReportService.getCommentReportPage(pageReqVO);
        return success(pageResult);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出评论举报记录 Excel")
//    @PreAuthorize("@ss.hasPermission('wine:comment-report:export')")
//    @OperateLog(type = EXPORT)
//    public void exportCommentReportExcel(@Valid CommentReportPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<CommentReportDO> list = commentReportService.getCommentReportPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "评论举报记录.xls", "数据", CommentReportRespVO.class,
//                        BeanUtils.toBean(list, CommentReportRespVO.class));
//    }

}
